home *** CD-ROM | disk | FTP | other *** search
/ Programmers Heaven 2 / Programmers Heaven 2.iso / files / graphics / library / wgt51_r2.zip / WGT5 / EXAMPLES / WGT50.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-03  |  3.4 KB  |  90 lines

  1. /*
  2. ==============================================================================
  3.                       WordUp Graphics Toolkit Version 5.0                     
  4.                              Demonstration Program 50                         
  5.                                                                               
  6.  Proper joystick detection and initialization is demostrated within this     
  7.  file. The commands wcalibratejoystick, wcheckjoystick, winitjoystick, and   
  8.  wreadjoystick are used.                                                     
  9.                                                                               
  10.  *** PROJECT ***                                                             
  11.  This program requires the WGT5_WC.LIB and WJOY_WC.LIB files to be linked.   
  12.                                                                               
  13.  *** DATA FILES ***                                                          
  14.  None.                                                                       
  15.                                                            WATCOM C++ VERSION 
  16. ==============================================================================
  17. */
  18.  
  19. #include <stdlib.h>
  20. #include <conio.h>
  21. #include <wgt5.h>
  22. #include <wgtjoy.h>
  23.  
  24. void main (void)
  25. {
  26.   joystick joya;                        /* Structure for joystick A */
  27.   joystick joyb;                        /* Structure for joystick B */
  28.   int display_row;                      /* Row for status display */
  29.   int result;                           /* Result of joystick detection */
  30.   int joya_found = 0;                   /* 1 if joystick is found */
  31.   int joyb_found = 0;                   /* 1 if joystick is found */
  32.  
  33.   if ( !vgadetected () )
  34.   {
  35.     printf ("Error - VGA card required for any WGT program.\n");
  36.     exit (0);
  37.   }
  38.   printf ("WGT Example #50\n\n");
  39.   printf ("Joystick routines are demonstrated. Make sure at least one joystick is\n");
  40.   printf ("connected in order to run the program.\n");
  41.   printf ("\n\nPress any key to continue.\n");
  42.   getch();
  43.  
  44.  
  45.   if (!( result = wcheckjoystick () ))
  46.   {
  47.     printf ("Joysticks not found. Program aborted.\n");
  48.     exit (0);
  49.   }
  50.  
  51.   if (result & 1)
  52.   {
  53.     joya_found = 1;                             /* It's there */
  54.     printf ("Joystick A detected.\n\n");
  55.     winitjoystick (&joya, 0);                   /* Initialize it */
  56.     printf ("Calibrate joystick A by swirling it and then pressing ENTER.\n");
  57.     wcalibratejoystick (&joya);
  58.     printf ("Joystick A calibrated.\n\n\n");
  59.   }
  60.  
  61.   if (result & 2)
  62.   {
  63.     joyb_found = 1;                             /* It's there */
  64.     printf ("Joystick B detected.\n\n");
  65.     winitjoystick (&joyb, 1);                   /* Initialize it */
  66.     printf ("Calibrate joystick B by swirling it and then pressing ENTER.\n");
  67.     wcalibratejoystick (&joyb);
  68.     printf ("Joystick B calibrated.\n\n\n");
  69.   }
  70.  
  71.   printf ("Now reading joystick values. Press any key to end program.\n\n");
  72.  
  73.   joya.scale = 2000;
  74.   joyb.scale = 2000;
  75.   while (!kbhit ())
  76.   {
  77.     if (joya_found)
  78.     {
  79.       wreadjoystick (&joya);            /* Read values into structures */
  80.       printf ("Joystick A       x: %5d    y: %5d    Buttons: %5d\n", joya.x, joya.y, joya.buttons);
  81.     }
  82.     if (joyb_found)
  83.     {
  84.       wreadjoystick (&joyb);
  85.       printf ("Joystick B       x: %5d    y: %5d    Buttons: %5d\n", joyb.x, joyb.y, joyb.buttons);
  86.     }
  87.   }
  88.   getch ();
  89. }
  90.